//
//  ReversiVirtualPlayers.m
//  Reversi
//
//  Created by 成瀬 龍人 on 2/10/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ReversiVirtualPlayers.h"


@implementation ReversiVirtualPlayers
- (void)loadPlugIns{
	playerClasses = [[NSMutableArray alloc] init];
	NSString* bundlePath = [[NSString alloc] initWithFormat:@"%@%@",[[NSBundle mainBundle] bundlePath],@"/Contents/PlugIns"];
	NSArray* paths = [NSBundle pathsForResourcesOfType:@"bundle" inDirectory:bundlePath];
	for(NSString* path in paths){
		NSBundle* bundle = [NSBundle bundleWithPath:path];
		[playerClasses addObject:[bundle principalClass]];
	}
}

- (id)createPlayerObjectAtIndex:(int)index{
	return [[[playerClasses objectAtIndex:index] alloc] init];
}

- (NSString*)descriptionAtIndex:(int)index{
	Class player = [playerClasses objectAtIndex:index];
	if ([player respondsToSelector:@selector(description)]){
		return [player description];
	}
	return @"";
}

- (int)numberOfItemsInComboBox:(NSComboBox*)aComboBox{
	return [playerClasses count];
}

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index{
	if ([[playerClasses objectAtIndex:index] respondsToSelector:@selector(name)]){
		return [[playerClasses objectAtIndex:index] name];
	}
	return [[playerClasses objectAtIndex:index] className];
}

- (int)numberOfRowsInTableView:(NSTableView*)tableView{
	return 5;
}

- (id)tableView:(NSTableView*)tableView objectValueForTableColumn:(int)col row:(int)row{
	return [[NSTextField alloc] init];
}

@end
